package com.fbs.controller;

import com.aaa.entity.Role;
import com.aaa.vo.Result;
import com.fbs.service.EERoleService;
import com.fbs.service.RRolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@Api("emp/role")
@RestController
@RequestMapping("emp/role")
@EnableSwagger2
public class RoleController {
    @Autowired
    private EERoleService roleService;
    @Autowired
    private RRolePermissionService rRolePermissionService;
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Role", name = "role", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("findAll")
    public Result findAll(@RequestBody Role role, Integer currentPage, Integer pageSize){
        Result all = roleService.findAll(role.getRoleName(), role.getStatus(), currentPage, pageSize);
        return all;
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Role", name = "role", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("insert")
    public Result insert(@RequestBody Role role){
        return roleService.insert(role);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Role", name = "role", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("update")
    public Result update(@RequestBody Role role){
        return roleService.update(role);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("delete/{id}")
    public Result delete(@PathVariable Integer id){

        return roleService.delete(id);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "id", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "status", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("updatestatus/{id}/{status}")
    public Result updatestatus(@PathVariable String id,@PathVariable String status){
        return roleService.updateStatrs(id,status);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("findPermissionAll")
    public Result findPermissionAll(String id){
        return roleService.findPermissionAll(id);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "id", value = "", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "List<String>", name = "menuids", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("/addPermission/{id}")
    public Result addPermission(@PathVariable String id, @RequestBody List<String>  menuids){
        Result result = rRolePermissionService.addPermission(id, menuids);
        return result;
    }
}
